package com.ghck.server.service.impl;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ghck.server.dao.DiseaseSearchHistoryMapper;
import com.ghck.server.model.DiseaseSearchHistory;
import com.ghck.server.model.query.DiseaseSearchHistoryQuery;
import com.ghck.server.service.DiseaseSearchHistoryService;

/**
 * 疾病搜索历史记录  <br>
 * t_disease_search_history <br>
 * v1.0 2016-05-01
 */
 @Service
 @Transactional
 public class DiseaseSearchHistoryServiceImpl implements DiseaseSearchHistoryService {
	
	private static final Logger logger = LoggerFactory.getLogger(DiseaseSearchHistoryServiceImpl.class);
	
	@Autowired
	private DiseaseSearchHistoryMapper diseaseSearchHistoryMapper;
	
	/**
 	*根据ID删除 疾病搜索历史记录
 	*/
 	@Override
 	public Integer deleteDiseaseSearchHistoryById(Integer id){
 		return diseaseSearchHistoryMapper.deleteById(id);
 	}
 	
 	/**
 	*新增 疾病搜索历史记录
 	*/
 	@Override
 	@Transactional
 	public Integer batchInsertDiseaseSearchHistory(List<? extends DiseaseSearchHistory> diseaseSearchHistorys){
		Integer count = diseaseSearchHistoryMapper.batchInsert(diseaseSearchHistorys);
		return count;
 	}
 	/**
 	*新增 疾病搜索历史记录
 	*/
 	@Override
 	@Transactional
 	public Integer insertDiseaseSearchHistory(DiseaseSearchHistory domain){
		Integer id = diseaseSearchHistoryMapper.insert(domain);
		return id;
 	}

 	/**
 	*更新 疾病搜索历史记录
 	*/
 	@Override
 	@Transactional
 	public Integer updateDiseaseSearchHistory(DiseaseSearchHistory domain){
		Integer count = diseaseSearchHistoryMapper.update(domain);
		return count;
 	}
 	
 	/**
 	*根据ID查询 疾病搜索历史记录
 	*/
 	public DiseaseSearchHistory findDiseaseSearchHistoryById(Integer id){
 		DiseaseSearchHistory result = diseaseSearchHistoryMapper.findById(id);
 		if(result!=null){
 			result.dealWith();
 		}
 		return result;
 	}

	/**
 	*通过query 查询 疾病搜索历史记录
 	*/
	public List<DiseaseSearchHistory> findDiseaseSearchHistoryByQuery(DiseaseSearchHistoryQuery query){
		query.dealWith();
		List<DiseaseSearchHistory> result = diseaseSearchHistoryMapper.findByQuery(query);
		if(CollectionUtils.isNotEmpty(result)) {
			for (DiseaseSearchHistory diseaseSearchHistory : result) {
				diseaseSearchHistory.dealWith();
			}
		}
		return result;
	}	
	
	/**
 	*通过query count总条数
 	*/
 	public Integer countDiseaseSearchHistoryByQuery(DiseaseSearchHistoryQuery query){
 		query.dealWith();
 		Integer result = diseaseSearchHistoryMapper.countByQuery(query);
 		return result;
 	}
 	
 	/**
 	* 通过ids查询
 	*/
 	public List<DiseaseSearchHistory> findDiseaseSearchHistoryByIds(List<Integer> ids){
 		List<DiseaseSearchHistory> result = diseaseSearchHistoryMapper.findByIds(ids);
		if(CollectionUtils.isNotEmpty(result)) {
			for (DiseaseSearchHistory diseaseSearchHistory : result) {
				diseaseSearchHistory.dealWith();
			}
		}
		return result;
 	}
 	
}	